package study.我的多线程四种方式.CallableInter;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableInterface0 implements Callable<Integer> {
	private int number =0  ;
	private   int staticVal=0;
	public CallableInterface0()
	{}
	public CallableInterface0(int num)
	{
		this.number=num;
	}

	public static void main(String[] args) {
		CallableInterface0 callableInterface0=new CallableInterface0();
		CallableInterface0 callableInterface02= new CallableInterface0(9);
		FutureTask< Integer>  futureTask = new FutureTask<>( callableInterface0 );
		FutureTask< Integer>  futureTask2 = new FutureTask<>( callableInterface02 );
		//产生2个线程
		Thread thread = new Thread(futureTask);
		thread.start();
		Thread thread2=new Thread(futureTask2);
		thread2.start();
		try {
			Integer intValue=futureTask.get();
			System.out.println("线程1返回的值为："+intValue);
			Integer intValue2=futureTask2.get();
			System.out.println("线程2返回的值为："+intValue2);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		} 
	}

	@Override
	public Integer call() throws Exception {
		System.out.println("子线程接收主线程入参："+
				(number==0?"没传值，默认":number)
				);
		return staticVal+number;
	}

}
